package logic

import (
	"context"
	"fmt"
	"gorm.io/gorm"
	"hotel/hotelrpc/hotelrpc"
	"hotel/hotelrpc/internal/svc"
	"hotel/model/mysql"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserUpLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserUpLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserUpLogic {
	return &UserUpLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserUpLogic) UserUp(in *hotelrpc.UserUpRequest) (*hotelrpc.UserUpResponse, error) {
	// todo: add your logic here and delete this line
	var findHotel mysql.Hotel
	mysql.DB.Debug().Where("id = ?", in.Id).Find(&findHotel)
	if findHotel.ID == 0 {
		return nil, fmt.Errorf("账号未登录,请登录账号")
	}
	hotel := mysql.Hotel{
		Model:       gorm.Model{ID: findHotel.ID},
		HeaderImage: in.HeaderImage,
		PerName:     in.PerName,
		Sex:         in.Sex,
		Name:        in.Name,
		PerInfo:     in.PerInfo,
	}
	mysql.DB.Debug().Updates(&hotel)
	return &hotelrpc.UserUpResponse{
		Id: int64(findHotel.ID),
	}, nil
}
